import {
  Toast
} from 'vant';

export const loading = (flag) => {
  if (flag) {
    Toast.loading({
      mask: true,
      message: '加载中...'
    });
  } else {
    Toast.clear();
  }
}

export function getCaption(obj) {
  if (obj) {
    var index = obj.lastIndexOf("\>");
    obj = obj.substring(index + 1, obj.length);
    //  console.log(obj);
    return obj;
  }
return "";
}

/**
 * This is just a simple version of deep copy
 * Has a lot of edge cases bug
 * If you want to use a perfect deep copy, use lodash's _.cloneDeep
 * @param {Object} source
 * @returns {Object}
 */
export function deepClone(source) {
  if (!source && typeof source !== 'object') {
    throw new Error('error arguments', 'deepClone')
  }
  const targetObj = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}